from flask import Flask, render_template
from flask_socketio import SocketIO
from flask import request
from flask_moment import Moment
from flask_mail import Mail
from flask_sqlalchemy import SQLAlchemy
from flask_login import login_manager
from config import configs

moment = Moment()
db = SQLAlchemy()
mail = Mail()
socketio = SocketIO()

def create_app(config_name):
    app = Flask(__name__)
    app.config.from_object(configs[config_name])
    configs[config_name].init_app(app)
    mail.init_app(app)
    moment.init_app(app)
    db.init_app(app)

    from app.main import main as main_blueprint
    app.register_blueprint(main_blueprint)

    socketio.init_app(app)

    return app